package com.andova.esgl.sample

import android.content.Context
import android.opengl.GLSurfaceView
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.andova.egl.Triangle
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class TriangleActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val glsv = GLSurfaceView(this)
        setContentView(glsv)
        glsv.setEGLContextClientVersion(3)
        glsv.setRenderer(Render(this))
    }
}

class Render(private val context: Context) : GLSurfaceView.Renderer {
    override fun onDrawFrame(gl: GL10?) = run { Triangle.drawFrame() }
    override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) = run { Triangle.surfCreated(context.assets) }
    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) = run { Triangle.surfChanged(width, height) }
}